package com.itheima.controller.backend.security;

import com.itheima.common.entity.Result2;
import com.itheima.pojo.SetmealPojo;
import com.itheima.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@Slf4j
public class FreeMarkerController {
    @Autowired
    private SetmealService setmealService;
    @GetMapping("/hello")
    public String hello(Model  model) {
        log.info("hello");
        model.addAttribute("name","itheima");
        return "01";
    }

    /**
     *  1.修改套餐列表页面为FreeMarker模板
     * @param id
     * @param mod
     * @return
     */
    @GetMapping("/findById")
    public String getById(Integer id, Model mod){

        log.info("查询套餐：{}",id);
        SetmealPojo setmeal = setmealService.getById(id);
        mod.addAttribute("setmeal",setmeal);
        return "mobile_setmeal_detail";
    }
/**
 * 2.修改套餐详情页面为FreeMarker模板
 * @param mod
 * @return
 */
    @GetMapping("/findAll")
    public  String findAll(Model  mod){
        log.info("查询所有套餐");
        List<SetmealPojo> list = setmealService.findAll();
        mod.addAttribute("list",list);
        return "mobile_setmeal";
    }
}
